<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新闻管理</title>
</head>
<script src="/qs.js"></script>
<script src="/axios.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="/vue.js"></script>
<body>
<div id="app">
    <table class="table">
        <thead>
        <tr>
            <th>标题</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="index in newsList">
            <td>{{index.title}}</td>
            <td>
                <a target="ges"  :href=`/updateNew.html${index.news_id}`>更新新闻</a>&nbsp;|
                <a target="ges" :href=`/previewNews.html?newsId=${index.news_id}`>预览</a>&nbsp;|
                <a target="ges" @click="delNews(`${index.news_id}`)" href="javascript:void(0)">删除新闻</a>
            </td>

        </tr>

        </tbody>
    </table>
</div>
</body>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                newsList:[],
                delModel:{}
            }
        },
        methods: {
            delNews(id){
                this.delModel = this.newsList.filter(f => f.news_id==id)[0]
                this.delModel.content.split("src");
                //要删除的新闻内容图片
                let array = this.delModel.content
                    .split("src")
                    .filter((f,index)=>index!=0)
                    .map(m=>{return m.split('"')})
                    .map(m=>{return m[1]});
                axios.post("/batchNews",{"url":array,"newsId":this.delModel.news_id,"coverUrl":this.delModel.cover_url})
                    .then(res=>{
                        window.location.href = "/newmanager.html";
                })
                console.log(array)
                //console.log(s.substring(3,s.indexOf()))
            }
        },
        created(){
            axios.get("/getAllNews").then(res=>{
                this.newsList = res.data;
            })
        }
    })
</script>
</html>